package com.ellricky.excute_president.ui.activity.home.task

import android.view.View
import com.ellricky.baselib.http.callback.ECallback
import com.ellricky.baselib.ui.base.BaseDetailActivity
import com.ellricky.excute_president.*
import kotlinx.android.synthetic.main.pd_activity_task_detail.*


class TaskDetailActivity : BaseDetailActivity() {

    private var pageType = -1

    override fun getChildContentLayout(): Int {
        return R.layout.pd_activity_task_detail
    }

    override fun initUIView() {
        super.initUIView()
        pageType = intent.getIntExtra(KEY_PAGE_TYPE, TASK_PAGE_OTHER)
        mTvTitle.text = getString(R.string.pd_task_detail)
        btnCancel.setOnClickListener(this)

        when (pageType) {
            TASK_PAGE_KX -> {
                tvAddress.visibility = View.GONE
                tvSaleCount.visibility = View.GONE
            }
            TASK_PAGE_ZX -> {
                tvScoreRemove.visibility = View.GONE
                tvAddress.visibility = View.GONE
                tvHour.visibility = View.GONE
            }
            TASK_PAGE_DT -> {
                tvSaleCount.visibility = View.GONE
                tvLine.visibility = View.GONE
                tvHour.visibility = View.GONE
            }
            else -> {
                tvScoreRemove.visibility = View.GONE
                tvSaleCount.visibility = View.GONE
                tvLine.visibility = View.GONE
                tvHour.visibility = View.GONE
            }
        }



        loadDetailData(id)
    }

    private fun loadDetailData(id: String) {
        mPresenter.loadDetail(API_TASK_DETAIL, id, object : ECallback<PdTaskDetailEntity>(this) {
            override fun onSuccess(data: PdTaskDetailEntity?, msg: String) {

                tvTitle.text = data?.title

                tvTeacher.value = data?.name
                tvDate.value = getString(
                        R.string.base_date_area, data?.taskStartDate, data?.taskEndDate
                )

                tvScoreAdd.value = getString(R.string.base_score, data?.giveScore)
                tvScoreRemove.value = getString(R.string.base_score, data?.removeScore)

                tvAddress.value = data?.address

                tvSaleCount.value = getString(R.string.base_yuan, data?.sellPrice)

                when (pageType) {
                    TASK_PAGE_KX ->
                        tvLine.value = getString(R.string.base_rate, data?.taskLine)
                    else ->
                        tvLine.value = getString(R.string.base_yuan, data?.taskLine)

                }

                tvHour.value = data?.classNum

                tvContent.text = data?.taskText

            }
        })
    }


    override fun onClickView(v: View?) {
        super.onClickView(v)
        when (v) {
            btnCancel -> mPresenter.sendBackRequest(API_TASK_CANCEL, id)
        }

    }


}
